from allpairspy import AllPairs

from api_py.enums.cookie import Cookie
from api_py.generate_case.template import template_case
from api_py.utils.file_sys import write_json


username = [
    {"value": "addCounselor", "description": "用户名合法"},
    {"value": "add@@__Counselor", "description": "用户名存在特殊字符"},
    {"value": "counselor", "description": "用户名合法但重复"},
    {"value": "add", "description": "用户名长度小于4"},
    {"value": "addCounselor2addCounselor2addCounselor2", "description": "用户名长度大于24"},

]

password = [
    {"value": "addCounselor", "description": "合法密码"},
    {"value": "aaaa", "description": "长度小于6的密码"},
    {"value": "aaaaaaaaaaaaaaaaaaaaaaaaaa", "description": "长度大于20的密码"},
]

name = [
    {"value": "newName", "description": "名字合法"},
    {"value": "new_Name", "description": "名字存在非法字符"},
    {"value": "newNamenewNamenewName", "description": "名字长度大于15"},
    {"value": "newNamene###NamenewName", "description": "名字长度大于15且存在非法字符"},
]

gender = [
    {"value": "女", "description": "性别与合法身份证一致"},
    {"value": "男", "description": "性别与合法身份证不一致"},
    {"value": "无性别", "description": "性别非法"},
]

phoneNumber = [
    {"value": "11900000000", "description": "电话合法且唯一"},
    {"value": "15900000000", "description": "电话合法但不唯一"},
    {"value": "123", "description": "电话号码非法"},
]

idNumber = [
    {"value": "350781196403074025", "description": "身份证合法"},
    {"value": "35078119640307AAAA", "description": "身份证长度合法"},
    {"value": "AAAA", "description": "身份证完全非法"},
]

department = [
    {"value": "华东师范大学", "description": "所在部门"},
    {"value": "华东师###@@@@范大学", "description": "所在部门存在非法字符"},
]

title = [
    {"value": 3213, "description": "合法职称"},
]

cookies = [
    {"value": Cookie.ADMIN_COOKIE.value, "description": "管理员登录"},
    {"value": Cookie.SUPERVISOR_COOKIE.value, "description": "督导登录"},
    {"value": Cookie.COUNSELOR_COOKIE.value, "description": "咨询师登录"},
    {"value": Cookie.WEIXIN_COOKIE.value, "description": "微信访客登录"},
    {"value": Cookie.NULL_COOKIE.value, "description": "未登录"},
    {"value": Cookie.ERROR_COOKIE.value, "description": "其他Cookie"},
]

body = [
    {"value": "addCounselor", "description": "用户名合法"},
    {"value": "addCounselor", "description": "合法密码"},
    {"value": "newName", "description": "名字合法"},
    {"value": "女", "description": "性别与合法身份证一致"},
    {"value": "11900000000", "description": "电话合法且唯一"},
    {"value": "350781196403074025", "description": "身份证合法"},
    {"value": "华东师范大学", "description": "所在部门"},
    {"value": 3213, "description": "合法职称"},
]


def case09_user_ms_counselor(api_type):
    json_result = {}
    parameters = [username, password, name, gender, phoneNumber, idNumber, department, title]
    i = 0

    # 检测数据格式的用例
    for pairs in AllPairs(parameters):
        case = template_case()
        request = case["request"]
        # 设置请求体参数
        request["body"]["username"] = pairs[0]
        request["body"]["password"] = pairs[1]
        request["body"]["name"] = pairs[2]
        request["body"]["gender"] = pairs[3]
        request["body"]["phoneNumber"] = pairs[4]
        request["body"]["idNumber"] = pairs[5]
        request["body"]["department"] = pairs[6]
        request["body"]["title"] = pairs[7]
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookies[0]

        json_result[i] = case
        i += 1

    # 检查用户权限的用例
    for cookie in cookies:
        case = template_case()
        request = case["request"]
        # 设置请求体参数
        request["body"]["username"] = body[0]
        request["body"]["password"] = body[1]
        request["body"]["name"] = body[2]
        request["body"]["gender"] = body[3]
        request["body"]["phoneNumber"] = body[4]
        request["body"]["idNumber"] = body[5]
        request["body"]["department"] = body[6]
        request["body"]["title"] = body[7]
        # 设置请求头cookie
        request["headers"]["Cookie"] = cookie

        json_result[i] = case
        i += 1

    write_json(api_type.value[0]["file_name"], json_result)
